Skip to content

deps: move tree-sitter-language-pack to 1.x, with a clear error when a grammar cannot be downloaded - #156

Open
fabceolin wants to merge 2 commits into
FSoft-AI4Code:mainfrom
fabceolin:deps/language-pack-1x
Open

fabceolin wants to merge 2 commits into
FSoft-AI4Code:mainfrom
fabceolin:deps/language-pack-1x

Conversation

@fabceolin

Copy link
Copy Markdown
Contributor

Summary

Moves tree-sitter-language-pack from >=0.8.0,<0.9.0 to >=1.23.1,<2.0.0,
as agreed in #154. This is the first of two stacked PRs. The Lean 4 analyzer
follows on top of this branch.

Changes

  • Pins. pyproject.toml has >=1.23.1,<2.0.0, and requirements.txt has
    ==1.23.1. tree-sitter==0.26.0 does not change. Pack 1.x declares
    tree-sitter>=0.23.
  • Dart. The 1.x grammar parses Foo<T>(x) as a call whose
    argument_part holds type_arguments, not as a relational_expression.
    _process_chain now reads the type arguments from the call. Without this
    change, test_call_resolution_rules and test_riverpod_and_router_edges
    fail, because the Garage.open -> Item and carProvider -> Car edges are
    lost.
  • Download at build time. docker/Dockerfile downloads the grammars the
    analyzers load (dart, go, javascript, typescript, vue, zig), so
    the image runs offline.
  • Clear error with no network. Pack 1.x downloads each grammar on first
    use. Without network access, the first load raised a DownloadError that
    names a URL only. The per-file except blocks also caught it, so the
    language dropped out of the graph with a traceback for each file.
    • utils/grammars.py loads pack grammars through get_pack_parser. It
      changes the DownloadError into a GrammarUnavailableError that names the
      grammar, the cache folder and the t.download([...]) command.
    • analyze_code_files calls ensure_pack_grammars before the first file,
      so the run stops one time. The CLI shows the message through its usual
      Analysis failed: ... path.
    • PACK_GRAMMARS_BY_LANGUAGE lists the grammars that each language loads.
      A test checks that docker/Dockerfile downloads the same set.
  • Docs. There is a CHANGELOG entry, and the "Adding a language" step in
    guides/development.md now uses get_pack_parser.

Example message, with an empty cache and no network:

The tree-sitter grammar 'go' is not in ~/.cache/tree-sitter-language-pack/v1.23.1/libs
and could not be downloaded (Download error: Failed to fetch manifest from
https://github.com/xberg-io/tree-sitter-language-pack/releases/download/v1.23.1/parsers.json:
io: Connection refused (os error 111)). tree-sitter-language-pack downloads each
grammar on first use, so the first analysis of these files needs network access.
To prepare a machine without network access, run this once on a machine with
access and copy the cache folder: python -c "import tree_sitter_language_pack as t;
t.download(['dart', 'go', 'javascript', 'typescript', 'vue', 'zig'])"

Tests

  • tests/test_pack_grammars.py (new, 5 tests) covers the error message, that
    only the grammars of the present languages load, that the analysis stops
    before the first file, and that the Dockerfile list matches.
  • The full suite gives 673 passed and 1 failed, on pack 1.23.1 and on 1.24.0.
    test_doc_write_guard.py::test_warning_reports_rejected_tool_calls also
    fails on main (a1b9f4a) in a fresh install, so it is not related to this
    change.
  • ruff check and ruff format --check pass.
  • docker build -f docker/Dockerfile . passes. In the image, get_parser
    loads all six grammars with --network none.

Out of scope: the image still needs network access at import time, because
codewiki/src/be/utils.py loads the tiktoken cl100k_base encoding when the
module is imported. This is already so on main. I can open a separate issue.

Note: tests/test_pack_grammars.py is added with git add -f, because
.gitignore has tests/*, like the other test files.

Refs #154

🤖 Generated with Claude Code

fabceolin and others added 2 commits November 6, 2026 08:15
…ents from the call

The pin goes from >=0.8.0,<0.9.0 to >=1.23.1,<2.0.0. Grammars that 0.8
does not ship (Lean, among others) are only in 1.x.

The 1.x Dart grammar parses `Foo<T>(x)` as an identifier with a call
selector whose argument_part holds the type_arguments, not as a
relational expression. `_handle_generic_invocation` never saw it, so the
type-argument edges (`Garage.open -> Item`, `carProvider -> Car`) were
lost. `_process_chain` now takes them from the call. The relational
expression path stays for grammars that still misparse it.

1.x downloads each grammar on first use and caches it. The Docker image
fetches the grammars the analyzers load at build time, so it runs
offline.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… cannot be downloaded

tree-sitter-language-pack 1.x downloads each grammar on first use. Without
network access the first load raises a DownloadError that names a URL but
not the cause or the fix, and the per-file except blocks of the analyzers
swallow it, so the language drops out of the graph with a traceback per file.

`utils/grammars.py` loads pack grammars through `get_pack_parser`, which turns
the DownloadError into a GrammarUnavailableError that names the grammar, the
cache folder and the `t.download([...])` command. `analyze_code_files` calls
`ensure_pack_grammars` before the first file, so the run stops once.
`PACK_GRAMMARS_BY_LANGUAGE` lists the grammars each language loads, and a test
checks that docker/Dockerfile downloads the same set.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant